package com.offcn.exception;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName: PageExceptionHandler
 * @Description: 页面异常处理实现类
 * @Date: 2020/12/7 14:31
 */
public class PageExceptionHandler implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        String message=null;
        e.printStackTrace();
        if(e instanceof PageException){
            message = e.getMessage();
        }else {
            message="系统异常，请联系姚志杰";
        }
        ModelAndView mv=new ModelAndView();
        mv.addObject("message", message);
        mv.setViewName("error");
        return mv;
    }
}
